<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
    <!-- 准备一个容器 -->
    <div id="root">
        <h2>{{school.name}}</h2>
        <h2>{{school.address}}</h2>
        <h2>{{school.leader}}</h2>
        <!-- vue中undefined不展示 -->
        <h2>{{undefined}}</h2>
        <hr>
        <button @click="addProperty">添加一个性别属性,默认是男</button>
        <h2>学生姓名：{{student.name}}</h2>
        <h2 v-show="student.sex">学生姓别：{{student.sex}}</h2>
        <h2>学生年龄：真实{{student.age.rage}} 对外{{student.age.sage}}</h2>
        <ul>
            <li v-for="(f,index) in student.friends" :key="index">{{f.name}} {{f.age}}</li>
        </ul>
    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false; //阻止vue在启动时产生产提示

    let vm = new Vue({
        el: '#root',
        data() {
            return {
                school:{
                    name: '尚硅谷',
                    address: '北京',
                    leader:'男老师'
                },
                student: {
                    name: 'tom',
                    // sex:'男',
                    age: {
                        rage: 12,
                        sage: 18,
                    },
                    friends: [
                        {name: 'jerry',age:35},
                        {name: 'tony',age:36}
                    ]
                }
            }
        },
        methods: {
            addProperty(){
                // 不能加到vm上,也不能加到_data上
                // Vue.set(this.student,'sex','男')
                this.$set(this.student,'sex','男')
                
            }
        },
    })
</script>

</html>